#ifndef _NNSLITE_BUFFERED_HEAP_FILE_H_
#define _NNSLITE_BUFFERED_HEAP_FILE_H_

#include "nnsliteglobal.h"
#include "nnsliteheapfile.h"

/**
 * Definition of buffered Heap file
 * */
typedef struct nnsliteBufferedHeapFile
{
	nnsliteHeapFile* hf; /* the primative heap file */
	u8* wbuf;            /* writing buffer */
	u64 wbufsize;        /* the used size of writing buffer */
	u64 wbufcapacity;    /* the capacity of the writing buffer */
	u64 wbufaddr;        /* the address of the beginning at the primative heap file */
	u8* rbuf;            /* reading buffer */
	u64 rbufendpos;      /* the end position of reading buffer */
	u64 rbufstartpos;    /* the start position of reading buffer */
	u64 rbufcapacity;    /* the capacity of the reading buffer */
	u64 rbufaddr;        /* the address of the beginning at the primative heap file */
}nnsliteBufferedHeapFile;

/**
 * Definition of the scanner of the buffered heap file
 * Note: The scanner can only read, not write.
 */
typedef struct nnsliteBufferedHeapFileScanner
{
	nnsliteBufferedHeapFile *bhf; /* the original buffered heap file */
	u8* rbuf;            /* reading buffer */
	u64 rbufendpos;      /* the end position of reading buffer */
	u64 rbufstartpos;    /* the start position of reading buffer */
	u64 rbufcapacity;    /* the capacity of the reading buffer */
	u64 rbufaddr;        /* the address of the beginning at the primative heap file */
}nnsliteBufferedHeapFileScanner;

NNSLITE_RET nnsliteBufferedHeapFileOpenNew(nnsliteHeapFS* heapFS, nnsliteBufferedHeapFile* bhf, u64 bufsize, u32 hfd);
NNSLITE_RET nnsliteBufferedHeapFileOpen(nnsliteHeapFS* heapFS, u32 hfd, nnsliteBufferedHeapFile* bhf, u64 bufsize);
NNSLITE_RET nnsliteBufferedHeapFileClose(nnsliteBufferedHeapFile* bhf);

NNSLITE_RET nnsliteBufferedHeapFileWrite(nnsliteBufferedHeapFile* bhf, const void* buf, u64 bufsize);
NNSLITE_RET nnsliteBufferedHeapFileFlush(nnsliteBufferedHeapFile* bhf);

NNSLITE_RET nnsliteBufferedHeapFileBeginRead(nnsliteBufferedHeapFile* bhf);
NNSLITE_RET nnsliteBufferedHeapFileRead(nnsliteBufferedHeapFile* bhf, void* buf, u64 bufsize);



















#endif

